#include <iostream>
#include <algorithm>
#include <vector>
#include <deque>

using namespace std;

struct score_t
{
	double count;
	double score;
};

bool operator < (const score_t &a, const score_t &b)
{
	return a.score > b.score;
}

score_t s[1000];

int main()
{
	int nCase;
	int n, m;
	
	cin >> nCase;
	while (nCase--)
	{
		cin >> n >> m;
		double sumS = 0;
		double sumC = 0;
		for (int i = 0; i < n; ++i)
		{
			double a, b;
			cin >> a >> b;
			sumC += b;
			sumS += a * b;
		}
		
		vector<double> queue[6];
		vector<double> sum[6];

		for (int i = 0; i < m; ++i)
		{
			double a;
			int b;
			cin >> a >> b;
			
			
			if (a > 90)
				queue[b].push_back(-a);
		}
		
		for (int i = 1; i <= 5; ++i)
		{
			sort(queue[i].begin(), queue[i].end());
			sum[i].push_back(0);
			for (int j = 0; j < queue[i].size(); ++j)
			{
				queue[i][j] = - queue[i][j];
				sum[i].push_back(sum[i][j] + queue[i][j]);
			}
		}
		
		int ret = m + 1;
		for (int a = 0; a <= queue[1].size(); ++a)
		for (int b = 0; b <= queue[2].size(); ++b)
		for (int c = 0; c <= queue[3].size(); ++c)
		for (int d = 0; d <= queue[4].size(); ++d)
		for (int e = 0; e <= queue[5].size(); ++e)
		    if (a + b + c + d + e < ret &&
				(sumS + sum[1][a] * 1 + sum[2][b] * 2 + sum[3][c] * 3 + sum[4][d] * 4 + sum[5][e] * 5) /
				(sumC + a * 1 + b * 2 + c * 3 + d * 4 + e * 5) >= 90)
				{
					ret = a + b + c + d + e;
				}

		if (ret > m)
			cout << "Impossible" << endl;
		else
		    cout << ret << endl;
	}
}
